package
{
	import alternativa.engine3d.core.Mesh;
	import alternativa.engine3d.materials.FillMaterial;

	public class Escalier extends Mesh
	{
		private var dist:Number = 15;
		private var longueur:Number = 200;
		private var id:Number = 0;
		private var xcoord:Number = 0;
		private var ycoord:Number = 0;
		private var zcoord:Number = 0;
		private var p0f:Number = 0;
		private var p1f:Number = 0;
		private var p2f:Number = 0;
		private var p3f:Number = 0;
		private var face:String;

		public function Escalier()
		{
			createmarchev();
			createmarchef();
			createmarchevr();
			createmarchefrs();
			moveAllFacesToSurface("temp");
			setMaterialToSurface(new FillMaterial(0xCCCCCC,1,"normal",1,0x000000),"temp");
		}

		public function createmarchev():void
		{
			xcoord = 0;
			ycoord = 0;
			zcoord = 0;
			id = 0  ;
			//Aller
			for (var i:int = 0 ; i<= 20; i++)
			{
				createVertex(xcoord,ycoord,zcoord,id);
				id += 2;
				if ( i & 1)
				{
				   zcoord += 15;
				}
				else
				{
				   ycoord += 15;
				}
			}
			xcoord =longueur;
			ycoord = 0;
			zcoord = 0;
			id = 1  ;
			for (var y:int; y<= 20; y++)
			{
				createVertex(xcoord,ycoord,zcoord,id);
				id += 2;
				if ( y & 1)
				{
				   zcoord += 15;
				}
				else
				{
				   ycoord += 15;
				}
			}
		}


		public function createmarchef():void
		{
			id = 0;
			p0f = 0;
			p1f = 1;
			p2f = 3;
			p3f =2;
			face = "f"
			for (var i:int = 0; i<=19; i++)
			{
				createFace([p0f,p1f,p2f,p3f],face + id);
				createFace([p3f,p2f,p1f,p0f],face +"inv"+ id);
				id++;
				p0f += 2;
				p1f += 2;
				p2f += 2;
				p3f += 2;
			}

		}

		public function createmarchevr():void
		{
			xcoord = longueur;
			ycoord = 150;
			zcoord = 150;
			id = 50  ;
			//Retour
			for (var i:int = 0 ; i<= 20; i++)
			{
				createVertex(xcoord,ycoord,zcoord,id);
				id += 2;
				if ( i & 1)
				{
				   zcoord += 15;
				}
				else
				{
				   ycoord -= 15;
				}
			}
			xcoord =longueur * 2;
			ycoord = 150;
			zcoord = 150;
			id = 51  ;
			for (var y:int; y<= 20; y++)
			{
				createVertex(xcoord,ycoord,zcoord,id);
				id += 2;
				if ( y & 1)
				{
				   zcoord += 15;
				}
				else
				{
				   ycoord -= 15;
				}
			}
		}

			public function createmarchefrs():void
		{
			id = 50;
			p0f = 50;
			p1f = 51;
			p2f = 53;
			p3f =52;
			face = "f"
			for (var i:int = 0; i<=19; i++)
			{
				createFace([p0f,p1f,p2f,p3f],face + id);
				createFace([p3f,p2f,p1f,p0f],face +"inv"+ id);
				id++;
				p0f += 2;
				p1f += 2;
				p2f += 2;
				p3f += 2;
			}
		}
	}
}